home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Games / Starter / JST / Developer / sources / src / loaders / Menace / menacehd.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-03  |  6.9 KB  |  504 lines

  1. ; *** Written by Jean-François Fabre
  2.  
  3. DISK_SIZE = 979600
  4.  
  5. HDLOAD = 1
  6. ;PATCH_LOGGED = 1
  7.  
  8.     include    "jst.i"
  9.  
  10.     HD_PARAMS    "menace.d",DISK_SIZE,1
  11.  
  12. BUILD_BLITWAIT_REG:MACRO
  13. WaitBlit\1A6:
  14.     move.w    \1,($58,A6)
  15.     WAIT_BLIT
  16.     rts
  17.     ENDM
  18.     
  19. loader:
  20.     RELOC_MOVEL    D0,trainer
  21.     RELOC_MOVEL    D4,buttonwait
  22.  
  23.     move.l    #20000,D0
  24.     JSRABS    AllocExtMem
  25.     tst.l    D0
  26.     beq    MemErr
  27.     add.l    #15000,D0
  28.     RELOC_MOVEL    D0,StackZone
  29.  
  30.     Mac_printf    "Menace HD Loader & fix v1.2"
  31.     Mac_printf    "Coded by Jean-François Fabre © 1998-1999"
  32.  
  33.     RELOC_TSTL    trainer
  34.     beq    skip$
  35.  
  36. ;    NEWLINE
  37. ;    Mac_printf    "Trainer activated"
  38. skip$
  39.     bsr    ReadScores
  40.     JSRABS    LoadDisks
  41.  
  42.     moveq.l    #0,D0
  43.     move.l    #CACRF_CopyBack,D1
  44.     JSRABS    Degrade
  45.  
  46.     GO_SUPERVISOR
  47.     SAVE_OSDATA    $80000
  48.  
  49.     JSRGEN    FreezeAll
  50.     move    #$2700,SR
  51.  
  52.     bsr    InstallBoot
  53.  
  54.     ; *** boot stuff and patch
  55.  
  56.     JSRGEN    FlushCachesHard
  57.  
  58.     jmp    $2000C
  59.  
  60. ReplaceBlitsAndCop:
  61.  
  62.     ; blitter fixes
  63.  
  64.     PATCHUSRJMP    $CC.W,WaitBlitD3A6
  65.     PATCHUSRJMP    $D2.W,WaitBlitD1A6
  66.     PATCHUSRJMP    $D8.W,WaitBlitD0A6
  67.     PATCHUSRJMP    $DE.W,StoreCopperPtr
  68.  
  69.     ; insert blitter waits
  70.  
  71.     move.l    #$3D430058,D0
  72.     move.l    #$4EB800CC,D1
  73.     lea    $70000,A0
  74.     lea    $74000,A1
  75.     JSRGEN    HexReplaceLong
  76.  
  77.     move.l    #$3D410058,D0
  78.     move.l    #$4EB800D2,D1
  79.     lea    $70000,A0
  80.     lea    $74000,A1
  81.     JSRGEN    HexReplaceLong
  82.  
  83.     ; ingame iconify
  84.  
  85.     move.l    #$2D480080,D0
  86.     move.l    #$4EB800DE,D1
  87.     lea    $6FA00,A0
  88.     lea    $73500,A1
  89.     JSRGEN    HexReplaceLong
  90.  
  91.     ; blitter waits (2)
  92.  
  93.     lea    $70000,A0
  94.     lea    $74000,A1
  95.     moveq    #6,D0        ; ($58,A6)
  96.     move.l    #14,D1        ; trap #$E (total random)
  97.     JSRGEN    PatchMoveBlit_Idx
  98.     rts
  99.  
  100. PatchMain:
  101.     cmp.l    #$08B90002,$72B74
  102.     beq    PatchMain_1
  103.     cmp.l    #$08B90002,$72BAA
  104.     beq    PatchMain_2
  105.     lea    VerErr(pc),A0
  106.     JSRGEN    SetExitRoutine
  107.     JSRGEN    InGameExit
  108.     bra    PatchMain
  109.  
  110. PatchMain_1
  111.     STORE_REGS
  112.  
  113.     move.l    #$25000,$72EC0
  114.  
  115.     ; ooops, forgot a BRA
  116.  
  117.     REGISTER_PATCH    $6F9EC,#8
  118.     move.w    #$601A,$6F9EC
  119.  
  120.     ; remove reloc stack at $7FFFE
  121.  
  122.     REGISTER_PATCH    $6FA28,#8
  123.     move.w    #$6004,$6FA28
  124.  
  125.     ; remove disk stuff
  126.  
  127.     PATCH_RTS    $72DBC
  128.     PATCH_RTS    $72E0C
  129.     PATCH_RTS    $72E28
  130.  
  131.     ; hiscores read
  132.  
  133.     PATCHUSRJMP    $72AAC,ReadTracks3
  134.  
  135.     ; disk loading 2
  136.  
  137.     PATCHUSRJMP    $72B74,ReadTracks2
  138.  
  139.     ; hiscores write
  140.  
  141.     PATCHUSRJMP    $72BC4,HiSave
  142.  
  143.     ; remove caches off
  144.  
  145.     REGISTER_PATCH    $72A86,#8
  146.     move.w    #$6020,$72A86
  147.  
  148.     ; keyboard int
  149.  
  150.     PATCHUSRJMP    $7167A,KbInt
  151.  
  152.     ; keyboard delay fixed
  153.  
  154.     PATCHUSRJSR    $71664,KbDelay
  155.  
  156.     ; remove original blitter wait
  157.  
  158.     PATCH_RTS    $73304
  159.  
  160.     bsr    ReplaceBlitsAndCop
  161.  
  162.     REGISTER_PATCH    $715B6,#4
  163.     REGISTER_PATCH    $715C6,#4
  164.     move.l    #$4EB800D8,$715B6
  165.     move.l    #$4EB800D8,$715C6
  166.  
  167.     RESTORE_REGS
  168.     rts
  169.  
  170. PatchMain_2:
  171.     STORE_REGS
  172.  
  173.     ; believe it or not, the game reads the ROM
  174.     ; to get a pseudo-random pattern for the stars
  175.     ; in the intro sequence! With $25000 it works
  176.     ; rather fine too.
  177.  
  178.     move.l    #$25000,$72EF6
  179.  
  180.     ; ooops, forgot a BRA
  181.  
  182.     REGISTER_PATCH    $6F9EC,#8
  183.     move.w    #$601A,$6F9EC
  184.  
  185.     ; blitter waits and copper store
  186.  
  187.     bsr    ReplaceBlitsAndCop
  188.  
  189.     ; remove reloc stack at $7FFFE
  190.  
  191.     REGISTER_PATCH    $6FA28,#8
  192.     move.w    #$6004,$6FA28
  193.  
  194.     ; remove disk stuff
  195.  
  196.     PATCH_RTS    $72DF2
  197.     PATCH_RTS    $72E42
  198.     PATCH_RTS    $72E5E
  199.  
  200.     ; hiscores read
  201.  
  202.     PATCHUSRJMP    $72ABE,ReadTracks3
  203.  
  204.     ; disk loading 2
  205.  
  206.     PATCHUSRJMP    $72BAA,ReadTracks2
  207.  
  208.     ; hiscores write
  209.  
  210.     PATCHUSRJMP    $72BFA,HiSave
  211.  
  212.     ; remove caches off
  213.  
  214.     REGISTER_PATCH    $72B84,#8
  215.     move.w    #$6020,$72B84
  216.  
  217.     ; keyboard int
  218.  
  219.     PATCHUSRJMP    $71724,KbInt
  220.  
  221.     ; keyboard delay fixed
  222.  
  223.     PATCHUSRJSR    $7170E,KbDelay
  224.  
  225.     ; remove original blitter wait
  226.  
  227.     PATCH_RTS    $7333A
  228.  
  229.     ; some other ones
  230.  
  231.     REGISTER_PATCH    $715B6,#4
  232.     REGISTER_PATCH    $715C6,#4
  233.     move.l    #$4EB800D8,$715B6
  234.     move.l    #$4EB800D8,$715C6
  235.  
  236.     RESTORE_REGS
  237.     rts
  238.  
  239. Jump1B0:
  240.     bsr    PatchMain
  241.     JSRGEN    FlushCachesHard
  242.     lea    $8494,A4
  243.     move.l    (A7)+,A5
  244.  
  245.     move.l    StackZone(pc),A7
  246.  
  247.     nop
  248.     nop
  249.     jsr    (A5)
  250.     nop
  251.     nop
  252.  
  253.     ; *** relocate stack
  254.  
  255.     move.l    StackZone(pc),A7
  256.  
  257. ;    lea    $7FFFE,A7    ; original $7FFFF
  258.     JSRGEN    FlushCachesHard
  259.     jmp    $50370
  260.  
  261. Jump18E:
  262.     PATCHUSRJMP    $71C4.W,ReadTracks
  263.  
  264.     REGISTER_PATCH $733E,#2
  265.     REGISTER_PATCH $72F4,#2
  266.  
  267.     move.w    #$4E75,$733E.W    ; disk stuff
  268.     move.w    #$4E75,$72F4.W    ; disk stuff
  269.  
  270.     GETUSRADDR    side_flag
  271.  
  272.     REGISTER_PATCH $70CC,#4
  273.     move.l    D0,$70CC.W
  274.  
  275.     REGISTER_PATCH $7116,#4
  276.     move.l    D0,$7116.W
  277.  
  278.     REGISTER_PATCH $714C,#4
  279.     move.l    D0,$714C.W
  280.  
  281.     REGISTER_PATCH $719C,#4
  282.     move.l    D0,$719C.W
  283.  
  284.     JSRGEN    FlushCachesHard
  285.     nop
  286.     nop
  287.     jmp    $708E.W
  288.     nop
  289.     nop
  290.  
  291.  
  292. Jump140:
  293.     PATCHUSRJMP    $18E.W,Jump18E
  294.     PATCHUSRJMP    $1B0.W,Jump1B0
  295.     JSRGEN    FlushCachesHard
  296.     nop
  297.     nop
  298.     jmp    $140.W
  299.     nop
  300.     nop
  301.  
  302.     BUILD_BLITWAIT_REG    D0
  303.     BUILD_BLITWAIT_REG    D1
  304.     BUILD_BLITWAIT_REG    D3
  305.  
  306. StoreCopperPtr:
  307.     move.l    D0,-(A7)
  308.     move.l    A0,D0
  309.     JSRGEN_FREEZE    StoreCopperPointer
  310.     move.l    A0,($80,A6)            ; original game
  311.     move.l    (A7)+,D0
  312.     rts
  313.  
  314. KbInt:
  315.     cmp.b    #$5F,D0
  316.     bne    noquit$
  317.     JSRGEN_FREEZE    InGameExit
  318. noquit$
  319.     cmp.b    #$42,D0
  320.     bne    noicon$
  321.     JSRGEN_FREEZE    InGameIconify
  322. noicon$
  323.     movem.l    (A7)+,D0-D1/A5-A6
  324.     rte
  325.  
  326. KbDelay:
  327.     BEAM_DELAY    #2
  328.     rts
  329.  
  330. ReadTracks3:
  331.     movem.l    D0-D6/A1-A6,-(sp)
  332.     bcc.b    nos1$        ; one of input params is C flag of CCR !
  333.  
  334.     add.l    #78,D0        ; side 1
  335. nos1$
  336.     clr.b    ($1F,A5)
  337.  
  338.     RELOC_TSTL    buttonwait
  339.     beq    skbw$
  340. bw$
  341.     btst    #7,$BFE001
  342.     bne    bw$
  343. skbw$
  344.  
  345.     lea    hiscbuff(pc),A2
  346.     cmp.l    #'FUCK',(A2)
  347.     beq    RT_Common    ; read hiscores from disk image if none
  348.  
  349.     ; xfer the hiscores to memory
  350.  
  351.     move.w    #$13F,D0
  352. copy$
  353.     move.b    (A2)+,(A0)+
  354.     dbf    D0,copy$
  355.  
  356.     movem.l    (sp)+,D0-D6/A1-A6
  357.     rts
  358.  
  359.  
  360. ReadTracks2:
  361.     movem.l    D0-D6/A1-A6,-(sp)
  362.     bcc.b    nos1$        ; one of input params is C flag of CCR !
  363.  
  364.     add.l    #78,D0        ; side 1
  365. nos1$
  366.     bra    RT_Common
  367.  
  368. ReadTracks:
  369.     movem.l    D0-D6/A1-A6,-(sp)
  370.  
  371.     move.b    side_flag(pc),D3
  372.     btst    #2,D3
  373.     beq    nos1$
  374.  
  375.     add.l    #78,D0        ; side 1
  376.  
  377. nos1$
  378.  
  379.     addq.l    #1,D1        ; first load uses D1+1
  380.  
  381. RT_Common
  382.     and.l    #$FFFF,D0
  383.     and.l    #$FFFF,D1
  384.  
  385.     move.w    D0,D3        ; save D0 in D3
  386.     move.l    A0,A1        ; save A0 in A1
  387.  
  388.     mulu    #$1838,D0
  389.     mulu    #$1838,D1    ; length
  390.     move.l    D0,D2        ; offset
  391.     moveq    #0,D0
  392.  
  393.     ; got to read the disk (JST call) with interrupts off
  394.     ; because the game accesses A5 during interrupts
  395.  
  396.     JSRGEN_FREEZE    ReadDiskPart
  397.  
  398.     add.l    D1,A0        ; A0 increase
  399.  
  400.     movem.l    (sp)+,D0-D6/A1-A6
  401.  
  402.     add.w    D1,D0
  403.  
  404.     move.l    #$FFFF,D1
  405.     rts
  406.     
  407. HiSave:
  408.     STORE_REGS
  409.  
  410.     lea    hiscbuff(pc),A1
  411.  
  412.     move.w    #$13F,D0
  413. copy$
  414.     move.b    (A0)+,(A1)+
  415.     dbf    D0,copy$
  416.  
  417.     lea    WriteScores(pc),A0
  418.     JSRGEN    SetExitRoutine
  419.  
  420.     RESTORE_REGS
  421.     rts
  422.  
  423.  
  424. ReadBoot:
  425.     lea    boot(pc),A0
  426.     lea    $400(A0),A0
  427.     lea    $10000,A5
  428.     move.l    A5,A1
  429.     MOVE.W    #$2FF,D0
  430. copy$
  431.     MOVE.L    (A0)+,(A1)+
  432.     DBF    D0,copy$
  433.     JSRGEN    FlushCachesHard
  434.     JMP    $20046
  435.     
  436. InstallBoot:
  437.     lea    boot(pc),A0
  438.     lea    $20000,A1
  439.     MOVE.W    #$FF,D0
  440. copy$
  441.     MOVE.L    (A0)+,(A1)+
  442.     DBF    D0,copy$
  443.  
  444.     PATCHUSRJMP    $2000E,ReadBoot
  445.     PATCHUSRJMP    $200A6,Jump140
  446.     rts
  447.  
  448.  
  449. WriteScores:
  450.     lea    hiscname(pc),A0
  451.     lea    hiscbuff(pc),A1
  452.     moveq    #0,D0
  453.     move.l    #$140,D1
  454.     JSRGEN    WriteUserFileHD
  455.     tst.l    D0
  456.     beq    ok$
  457.     Mac_printf    "** Unable to save hiscores. Hit RETURN"
  458.     JSRABS    WaitReturn
  459. ok$
  460.     rts
  461.  
  462. ReadScores:
  463.     lea    hiscname(pc),A0
  464.     lea    hiscbuff(pc),A1
  465.     moveq    #0,D0
  466.     move.l    #$140,D1
  467.     JSRGEN    ReadUserFileHD
  468.     tst.l    D0
  469.     beq    ok$
  470.     Mac_printf    "** Unable to read hiscores."
  471. ok$
  472.     rts
  473.  
  474.  
  475. MemErr:
  476.     Mac_printf    "** Not enough memory!"
  477.     JSRABS    CloseAll
  478.  
  479. VerErr:
  480.     Mac_printf    "** Unsupported version. Hit return"
  481.     JSRABS    WaitReturn
  482.     rts
  483.  
  484. StackZone:
  485.     dc.l    0
  486.  
  487. trainer:
  488.     dc.l    0
  489. buttonwait:
  490.     dc.l    0
  491.  
  492. side_flag:
  493.     dc.l    0
  494.  
  495. hiscname:
  496.     dc.b    "menace.hsc",0
  497.     cnop    0,4
  498.  
  499. hiscbuff:
  500.     dc.b    "FUCK"
  501.     blk.b    $140,0
  502. boot:
  503.     incbin    "menace.boot"
  504.